package com.unittec.drainage.gateway;

import com.unittec.drainage.gateway.filter.WebSocketFilter;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;

import com.unittec.drainage.provider.ApplicationContextProvider;

/**
 * @author wuxinwei
 */
@SpringBootApplication(scanBasePackages = {"com.unittec.drainage.provider", "com.unittec.drainage.gateway"},
    excludeName = {"com.baomidou.mybatisplus.autoconfigure.MybatisPlusAutoConfiguration",
        "org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration",
        "com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure"})
@EnableZuulProxy
@EnableDiscoveryClient
public class GateWayApplication {

    public static void main(String[] args) {
        try {
            SpringApplication.run(GateWayApplication.class, args);
            curEnvironmentOut();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Bean
    public WebSocketFilter webSocketFilter() {
        return new WebSocketFilter();
    }

    private static void curEnvironmentOut() {
        System.out.println("****************************************************************************");
        Environment env = ApplicationContextProvider.getBean(Environment.class);
        String profile = env.getProperty("spring.profiles.active");
        System.out.println("当前启动环境:" + profile);
        System.out.println("****************************************************************************");
    }
}
